package com.gitee.wsl.compose.ui.container.swipe

import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.SwipeToDismissBoxState
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp


@Composable
fun DeleteBackground(
  swipeDismissState: SwipeToDismissBoxState
) {
  val color by animateColorAsState(
    when (swipeDismissState.dismissDirection) {
      SwipeToDismissBoxValue.EndToStart -> Color.Red
      SwipeToDismissBoxValue.StartToEnd -> Color.Transparent
      else -> Color.Transparent
    }, label = ""
  )
  
  Box(
    modifier = Modifier
      .fillMaxSize()
      .background(color)
      .padding(16.dp),
    contentAlignment = Alignment.CenterEnd
  ) {
    Icon(imageVector = Icons.Default.Delete, contentDescription = "delete icon", tint = Color.White)
  }
}
